/*
 * @Author: hongbin
 * @Date: 2022-10-25 22:38:05
 * @LastEditors: hongbin
 * @LastEditTime: 2022-10-25 22:54:25
 * @Description: 清除对象所有子元素
 */

export function clearChildren(obj: THREEMesh) {
    //没有下面的while清理的干净 不知为何
    // obj.children.forEach((element) => {
    //     clearChildren(element);
    //     obj.remove(element);
    // });

    while (obj.children.length > 0) {
        clearChildren(obj.children[0]);
        obj.remove(obj.children[0]);
    }
    if (obj.geometry) obj.geometry.dispose();

    if (obj.material) {
        if (Array.isArray(obj.material)) {
            obj.material.forEach((m) => m.dispose());
        } else obj.material.dispose();
    }
}
